// TODO: deprecate this content being an elixir template and provide it entirely
// using Zig comptime logic.
beam.context.env = env;
beam.context.mode = .callback;
beam.context.allocator = beam.allocator;
<% name = @on_upgrade.name %>
<%= if @on_upgrade.arity == 3 do %>
// following type is guaranteed to exist as per semantic analysis.
const Payload = @typeInfo(@TypeOf(nif.<%= @on_upgrade.name%>)).@"fn".params[2].type.?;
const payload = beam.get(Payload, .{.v = load_info}, .{}) catch return -1;
<%= case @on_upgrade.return do %>
  <% %Zig.Type.Enum{} -> %>
return @intFromEnum(nif.<%= name %>(@ptrCast(priv_data), @ptrCast(old_priv_data), payload));
  <% %Zig.Type.Integer{} -> %>
return @intCast(nif.<%= name %>(@ptrCast(priv_data), @ptrCast(old_priv_data), payload));
  <% %Zig.Type.Error{child: :void} -> %>
nif.<%= name %>(@ptrCast(priv_data), @ptrCast(old_priv_data), payload) catch return -1;
return 0;
  <% :void -> %>
nif.<%= name %>(@ptrCast(priv_data), @ptrCast(old_priv_data), payload);
return 0;
<% end %>
<% else %>
return nif.<%= name %>(env, @ptrCast(priv_data), @ptrCast(old_priv_data), load_info);
<% end %>